﻿namespace sfcms.api
{
    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public abstract class webpagebase : Page
    {
        protected webpagebase()
        {
        }

        protected object[] GetFolderAndItemFromQueryString(int type)
        {
            long itemID;
            object[] variable0003;
            string nodeKey = base.Request.QueryString["key"];
            folder folderToReturn = (type == 1) ? folder.pageroot : folder.fileroot;
            string[] nodePath = nodeKey.Split(new char[] { '/' });
            long folderID = Convert.ToInt64(nodePath[0]);
            if (folderID > 0L)
            {
                folderToReturn = folder.byid(folderID);
            }
            if (!long.TryParse(nodePath[1], out itemID))
            {
                variable0003 = new object[2];
                variable0003[0] = folderToReturn;
                return variable0003;
            }
            if (itemID == 0L)
            {
                variable0003 = new object[2];
                variable0003[0] = folderToReturn;
                return variable0003;
            }
            object itemToReturn = (type == 1) ? ((object) page.fromid(itemID)) : ((object) file.fromid(itemID));
            return new object[] { folderToReturn, itemToReturn };
        }

        protected abstract void Page_Load();
        protected void Page_Load(object sender, EventArgs e)
        {
            base.Response.Expires = -1;
            if (user.current == null)
            {
                if (base.Request.Url.AbsolutePath.ToLowerInvariant().Contains("sfcms_jsserver.aspx"))
                {
                    base.Response.Write("document.location.href = '/';");
                }
                else
                {
                    base.Response.Redirect("/");
                }
            }
            else
            {
                this.Page_Load();
            }
        }

        protected void SetPageTitle(string title)
        {
            (base.Master.FindControl("title") as Literal).Text = title;
        }

        protected void SetWarningMessage(string warningMessage)
        {
            (base.Master.FindControl("warningmessage") as Literal).Text = warningMessage;
        }
    }
}

